package com.anivia.common.web.config.mybatisPlus;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.anivia.common.web.satoken.util.UserInfoUtil;
import com.baomidou.mybatisplus.extension.plugins.inner.DataChangeRecorderInnerInterceptor;

/**
 * 自定义mybatisPlus数据变动拦截插件
 *
 * @author wangj
 */
public class MyDataChangeRecorderInnerInterceptor extends DataChangeRecorderInnerInterceptor {
    @Override
    protected void dealOperationResult(OperationResult operationResult) {
        JSONObject param = JSONUtil.parseObj(operationResult);
        // 租户id
        param.putOpt("tenantId", UserInfoUtil.getTenantId());
        // 用户类型
        param.putOpt("userType", UserInfoUtil.getLoginType().getType());
        // 操作用户id
        param.putOpt("userId", UserInfoUtil.getLoginUserId());
        logger.info("数据变动记录: {}", JSONUtil.toJsonStr(param));
    }
}
